package biznussoft.metercor.fragments;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TimePicker;
import biznussoft.metercor.R;
import biznussoft.metercor.listener.DialogListener;
import biznussoft.metercor.utils.Session;



public class TimePickerDialogFragment  extends DialogFragment{

	DialogListener listener;
	Dialog  dialog;
	 public static DialogFragment newInstace() {
	        DialogFragment dialogFragment = new TimePickerDialogFragment();
	        return dialogFragment;
	    }
	 
	 @Override
	public void onAttach(Activity activity) {
		// TODO Auto-generated method stub
		super.onAttach(activity);
		listener = (DialogListener) getActivity();
	}
	 
	    @Override
	    public Dialog onCreateDialog(Bundle savedInstanceState) {
	    	
	    	 dialog = new Dialog(getActivity());
	         dialog.setTitle("Select Time");
	         dialog.setContentView(R.layout.timepickerdialog);
	         dialog.show();
	         
	         final TimePicker picker = (TimePicker) dialog.findViewById(R.id.timeEdit);
	         Button button = (Button) dialog.findViewById(R.id.btDone);
	         button.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					Log.i("TPT","Time  is   :"+picker.getCurrentHour().toString()+":"+picker.getCurrentMinute().toString())		;
					Session.sb.append(" ").append(picker.getCurrentHour().toString()).append(":").append(picker.getCurrentMinute().toString()).append(":").append("00");
					dialog.dismiss();
					listener.setDateTime(Session.sb);
				}
			});
	        /* Button cancel = (Button) dialog.findViewById(R.id.btCancel);
	         cancel.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					dialog.dismiss();
				}
			});*/
	         
	        
	    
	        return dialog;
	    }
	 
	    
}
